﻿#region License
// (c) Garry McGlennon 2009
// 
// This project is made available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// 
// View the project and the latest code at http://dnpframework.codeplex.com/
// 
// All other rights reserved.
// 
// blog: www.dotNetProfessional.com/blog/
#endregion
using System.IO;
using System.Net;

namespace dnp.Framework.Web
{
    /// <summary>
    /// Methods used to request data from the web
    /// </summary>
    public class Request
    {
        /// <summary>
        /// Returns the HTML from a Url as a single string.
        /// </summary>
        /// <param name="url">The web page to return</param>
        /// <returns>string representation of the HTML</returns>
        public virtual string GetHtml(string url)
        {
            string result;
            if (!url.StartsWith("http"))
                url = "http://" + url;

            WebRequest webRequest = WebRequest.Create(url);
            using (WebResponse webResponse = webRequest.GetResponse())
            {
                using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
                {
                    result = streamReader.ReadToEnd();
                }
            }
            return result;
        }
    }
}
